<script type="text/javascript">

    function on_submit(){
        var id_str="<?php echo $id_arr?>";
        var id_arr=id_str.split(',');
        var id=$('#post_id').val();
        var id_res = $.inArray(id, id_arr);
        if(id_res !== -1){
            alert('帖子已经加入推荐');
            return false;
        }
        if(id === ''){
            alert('请选择帖子！');
            return false;
        }
        var sort_arr_str="<?php echo $sort_arr_json?>";
        var sort_arr_arr=sort_arr_str.split(',');
        var sort=$('#sort').val();
        var sort_res = $.inArray(sort, sort_arr_arr);
        if(sort_res !== -1){
            alert('排序已经被使用过，请填写推荐排序');
            return false;
        }
        if(sort>5 || sort<1){
            alert('排序只能填写1-5，请填写推荐排序');
            return false;
        }
        $("#rule_form").submit();
    }
    function selShow(){
        var post_time = $("#post_time").val();
        if(post_time == -1){
            $("#set_post_time").show();
        }else{
            $("#set_post_time").hide();
        }
    }
    $("#add_rules").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
    });
</script>

<div class="tab-pane active" id="horizontal-form">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" aria-label="Close">×</button>
        <h2 class="modal-title">添加数据(<?php echo $topic['title']?>)</h2>
    </div>
    <form class="form-horizontal" name="form" id="rule_form" action="index.php?c=<?php echo $_REQUEST["c"]?>&m=<?php echo $_REQUEST["m"]?>" method="post">
        <input type="hidden" name="id" id="id" value="<?php echo $id;?>"/>
        <input type="hidden" name="submits" value="1"/>

        <div class="form-group">
            <label for="post_times" class="col-sm-2 control-label">帖子</label>
            <div class="col-sm-6">
                <div class="input-group suggests" style="margin-left:0px;width: 100%;">

                    <input type="text" placeholder="请输入标题" class="input-sm form-control" id="post_title" value="<?php echo isset($topic['post_title'])?$topic['post_title']:'';?>" onkeyup="getPostList()" autocomplete="off"/>
                    <ul class="dropdown-menu dropdown-menu-right" id="tag_menu"></ul>
                </div>
            </div>
            <div class="col-sm-2">
            </div>
        </div>
        <div class="form-group">
            <label for="post_times" class="col-sm-2 control-label">帖子id</label>
            <div class="col-sm-6">
                <div class="input-group suggests" style="margin-left:0px;width: 100%;">

                    <input type="text" name="post_id" class="input-sm form-control" id="post_id" value="<?php echo isset($topic['post_id'])?$topic['post_id']:'';?>" placeholder="请输入帖子id">
                    <ul class="dropdown-menu dropdown-menu-right" id="tag_menu"></ul>
                </div>
            </div>
            <div class="col-sm-2">
            </div>
        </div>
        <div class="form-group">
            <label for="post_times" class="col-sm-2 control-label">排序</label>
            <div class="col-sm-2">
                <input type="text" name="sort" id="sort" class="form-control"  value="1">
            </div>
            <div class="col-sm-5">
                可用排序为：<?php
                $sort=array(1,2,3,4,5);
                function myfunction($a,$b){if ($a===$b) {return 0;}return ($a>$b)?1:-1;}
                $arr=array_udiff($sort,$sort_arr,'myfunction');
//                print_r($arr);
                echo implode(',',$arr);
                ?>
            </div>
        </div>

        <div class="modal-footer">
            <button type="reset" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" onclick="on_submit()" class="btn btn-primary">保存</button>
        </div>

    </form>
</div>